home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / HELP.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  8KB  |  340 lines

  1. #include "pt.h"
  2. #include "string.h"
  3.  
  4. static int menuType;
  5. static int prevScreen = 100;
  6.  
  7. int pascal
  8. /* XTAG:help */
  9. help(index)
  10.     int index;
  11. {
  12.     extern unsigned char msgBuffer[];
  13.     extern unsigned char textBuffer[];
  14.     extern union REGS rin, rout;
  15.     extern int debug;
  16.     extern int scrRows, scrCols;
  17.     
  18.     long cp;
  19.     int n, fid, retValue;
  20.     unsigned char *p;
  21.  
  22.     p = findFile("pt.hlp");
  23.     if( p == NULL ) {
  24.         msg("Cannot find pt.hlp in PATH", 3);
  25.         return 0;
  26.     } else
  27.         fid = getFileId(p);
  28.  
  29.     retValue = 0;
  30.     n = index;
  31.     cp = 0;
  32.     while( n > 0 ) {
  33.         /* cp now points to the beginning of the next screen */
  34.         cp = findScreen(n, fid);
  35.  
  36.         /* cp now points to the data part of the screen */
  37.         /* after the screen header info has been read */
  38.         cp = showScreen(fid, cp, &n);
  39.  
  40.         if( n == -1 )
  41.             retValue = 1;
  42.     }
  43.     
  44.     closeFile(fid, 2);
  45.     redrawBox(0, 0, scrRows-1, scrCols-1);
  46.     updateScreen(0, scrRows-1);
  47.  
  48.     return retValue;
  49. }
  50.  
  51. /* list of goto pages from the page header */
  52. /* the first two are the previous (PgUp) and next (PgDn) pages */
  53. /* the rest are the 1-9,0 or a-t pages */
  54. int screens[22];
  55. int screenNumber;
  56.  
  57. int pascal
  58. /* XTAG:nextScreen */
  59. nextScreen()
  60. {
  61.     extern unsigned char msgBuffer[];
  62.     extern union REGS rin, rout;
  63.     extern struct event events[];
  64.     extern int mousePresent;
  65.  
  66.     int n, evhead;
  67.     unsigned char ch, scan;
  68.     
  69.     while( 1 ) {
  70.         /* any mouse button down? */
  71.         if( mousePresent && isMouseEvent(0) ) {
  72.             evhead = getMouseEvent();
  73.             switch( events[evhead].buttons ) {
  74.                 case 0:    /* no buttons */
  75.                     break;
  76.                 case 1:    /* left button */
  77.                     return prevScreen;
  78.                 case 2:    /* right button */
  79.                     return screens[1];
  80.                 default:    /* middle or both */
  81.                     return 0;
  82.             }
  83.         }
  84.         if( !isKeystroke() )
  85.             continue;
  86.         ch = getKeystroke(&scan);
  87.         switch( ch ) {
  88.         case 0:
  89.             switch( scan ) {
  90.             case 73:    /* PgUp */
  91.                 return prevScreen;
  92.             case 81:    /* PgDn */
  93.                 return screens[1];
  94.             default:
  95.                 goto defLabel;
  96.             }
  97.             break;
  98.         case '\r':    /* Enter key */
  99.         case ' ':    /* space bar */
  100.             return 0;
  101.         case 27:    /* ESCape key */
  102.             return -1;
  103.         case '0': case '1': case '2': case '3': case '4':
  104.         case '5': case '6': case '7': case '8': case '9':
  105.             n = screens[ch - '0' + 2];
  106.             if( n == -1 )
  107.                 goto defLabel;
  108.             return n;
  109.         case 'a': case 'b': case 'c': case 'd': case 'e':
  110.         case 'f': case 'g': case 'h': case 'i': case 'j':
  111.         case 'k': case 'l': case 'm': case 'n': case 'o':
  112.         case 'p': case 'q': case 'r': case 's': case 't':
  113.             n = screens[ch - 'a' + 2];
  114.             if( n == -1 )
  115.                 goto defLabel;
  116.             return n;
  117.         default:
  118.         defLabel:
  119.             msg("", 0);    /* blink the line */
  120.             msg(
  121. "Please make one of the choices listed above, PgDn (next), or PgUp(previous)",
  122. 2);
  123.             break;
  124.         }
  125.     }
  126. }
  127.  
  128. long pascal
  129. /* XTAG:findScreen */
  130. findScreen(n, fileId)
  131.     int n, fileId;
  132. {
  133.     extern unsigned char msgBuffer[];
  134.     extern unsigned char textBuffer[];
  135.     
  136.     long cp2;
  137.     register unsigned char *p;
  138.  
  139.     /* find the location of the screen in the index at the front */
  140.     (void) readLine(fileId, (long)(8*n), textBuffer, 0);
  141.     sscanf(textBuffer, "%ld", &cp2);
  142.  
  143.     /* now read the first line of the help screen description */
  144.     cp2 = readLine(fileId, cp2, textBuffer, 0);
  145.  
  146.     /* get the goto screen numbers on the header line */
  147.     n = 0;
  148.     p = &textBuffer[0];
  149.     while( n < 22 ) {
  150.         /* find the next blank */
  151.         p = strchr(p, ' ');
  152.         if( p == NULL )
  153.             break;
  154.         while( *p == ' ' || *p == '\t' || *p == '\r' || *p == '\n' )
  155.             ++p;
  156.         if( p == NULL )
  157.             break;
  158.         sscanf(p, "%d", &screens[n++]);
  159.     }
  160.     /* put the default values in the unspecified screen numbers */
  161.     while( n < 22 )
  162.         screens[n++] = -1;
  163.     return cp2;
  164. }
  165.  
  166. extern unsigned char far *menuSpace;
  167. extern int nextSpace;
  168.  
  169. long pascal
  170. /* XTAG:showScreen */
  171. showScreen(fileId, cp, next)
  172.     int fileId, *next;
  173.     long cp;
  174. {
  175.     extern unsigned char msgBuffer[];
  176.     extern unsigned char textBuffer[];
  177.     extern struct menuBlock far *menus[];
  178.     extern int scrCols;
  179.     
  180.     int n, iChar, iLine, iMenu, menuRow, menuCol;
  181.     unsigned char ch;
  182.     
  183.     /* see if this is a menu screen */
  184.     cp = readLine(fileId, cp, textBuffer, 0);
  185.     if( textBuffer[0] == '\\' ) {
  186.         /* no menu, must be a regular screen */
  187.         cp = dispScreen(fileId, cp);
  188.         n = nextScreen();
  189.         prevScreen = *next;    /* remember the last screen shown */
  190.         *next = n;
  191.         return cp;
  192.     }
  193.     /* read in the menu name */
  194.     iChar = nextSpace;
  195.     menus[0]->cmdName[0] = &menuSpace[iChar];
  196.     iLine = 1;    /* skip past the " */
  197.     while( 1 ) {
  198.         ch = textBuffer[iLine++];
  199.         if( ch == '"' || iLine >= scrCols )
  200.             break;
  201.         menuSpace[iChar++] = ch;
  202.     }
  203.     menuSpace[iChar++] = '\0';
  204.     sscanf(&textBuffer[iLine], "%d%d%d", &menuType, &menuRow, &menuCol);
  205.  
  206.     /* read in the menu strings */
  207.     menus[0]->cmdNumber[0] = 0;
  208.     iMenu = 1;
  209.     /* one iteration for each menu item */
  210.     while( 1 ) {
  211.         cp = readLine(fileId, cp, textBuffer, 0);
  212.         if( textBuffer[0] == '\\' )
  213.             break;
  214.         /* read in the string from the help file */
  215.         iLine = 1;    /* char 0 is the opening " */
  216.         menus[0]->cmdName[iMenu] = &menuSpace[iChar];
  217.         while( 1 ) {
  218.             ch = textBuffer[iLine++];
  219.             if( ch == '"' )
  220.                 break;
  221.             menuSpace[iChar++] = ch;
  222.             if( iChar >= MENUSPACE ) {
  223.                 sprintf(msgBuffer,
  224. "Menu too large before char position %ld in pt.hlp [space to continue]", cp);
  225.                 msg(msgBuffer,3);
  226.                 incon();
  227.                 goto error1;
  228.             }
  229.         }
  230.         menuSpace[iChar++] = '\0';
  231.         /* now get the screen number */
  232.         sscanf(&textBuffer[iLine], "%d", &n);
  233.         menus[0]->cmdNumber[iMenu] = n;
  234.         ++iMenu;
  235.         if( iMenu >= 22 ) {
  236.             sprintf(msgBuffer,
  237. "Menu too long before char position %ld in pt.hlp [space to continue]", cp);
  238.             msg(msgBuffer,3);
  239.             incon();
  240.             goto error1;
  241.         }
  242.     }
  243. error1:
  244.     menus[0]->nItems = iMenu;
  245.     cp = dispScreen(fileId, cp);
  246.     prevScreen = *next;    /* remember the last screen shown */
  247.     if( menuType == 1 ) {
  248.         n = menu(menus[0], menuRow, menuCol);
  249.     } else
  250.         n = nextScreen();
  251.     prevScreen = *next;    /* remember the last screen shown */
  252.     *next = n;
  253.     return cp;
  254. }
  255.  
  256. long pascal
  257. /* XTAG:dispScreen */
  258. dispScreen(fileId, cp)
  259.     int fileId;
  260.     long cp;
  261. {
  262.     extern unsigned char *screenChars;
  263.     extern int tabWidth;
  264.     extern unsigned char textColor, selColor;
  265.     extern int scrRows, scrCols;
  266.     extern unsigned char textBuffer[];
  267.  
  268.     long cp2;
  269.     int n, col, iText, moreLines;
  270.     int currentRow;
  271.     unsigned char ch, *p, *nextRow, attr;
  272.  
  273.     attr = textColor;
  274.     moreLines = 1;
  275.     currentRow = 0;
  276.     p = screenChars;
  277.     while( currentRow < scrRows ) {
  278.         if( moreLines ) {
  279.             cp2 = readLine(fileId, cp, textBuffer, 0);
  280.             if( textBuffer[0] == '\\' || cp2 == cp )
  281.                 moreLines = 0;
  282.         }
  283.         if( currentRow == scrRows - 1 ) {
  284.             moreLines = 1;
  285.             /* put this message on the bottom line */
  286.             strcpy(textBuffer,
  287. "\\bSpace\\r,\\bEsc\\r=return to Point           \\bPgDn\\r=next screen       \\bPgUp\\r=prev screen");
  288.         }
  289.         cp = cp2;
  290.         iText = 0;
  291.         col = 0;
  292.         nextRow = p + (scrCols<<1);
  293.         if( moreLines )
  294.             ch = 0;
  295.         else
  296.             ch = '\n';
  297.         while( ch != '\r' && ch != '\n' && p < nextRow ) {
  298.             ch = textBuffer[iText++];
  299.             switch( ch ) {
  300.             case '\n':
  301.             case '\r':
  302.                 attr = textColor;
  303.                 break;
  304.             case '\t':
  305.                 n = tabWidth - (col % tabWidth);
  306.                 col += n;
  307.                 while( n-- > 0 ) {
  308.                     *p++ = ' ';
  309.                     *p++ = attr;
  310.                 }
  311.                 break;
  312.             case '\\':
  313.                 ch = textBuffer[iText++];
  314.                 switch( ch ) {
  315.                 case 'b': attr = textColor|0x8; break;
  316.                 case 's': attr = selColor; break;
  317.                 case 'B': attr = selColor|0x80; break;
  318.                 case '\\': goto printBackSlash;
  319.                 default: attr = textColor; break;
  320.                 }
  321.                 break;
  322.             default:
  323.             printBackSlash:
  324.                 *p++ = ch;
  325.                 *p++ = attr;
  326.                 ++col;
  327.                 break;
  328.             }
  329.         }
  330.         /* fill the rest of the line with blanks */
  331.         while( p < nextRow ) {
  332.             *p++ = ' ';
  333.             *p++ = attr;
  334.         }
  335.         updateScreen(currentRow, currentRow);
  336.         ++currentRow;
  337.     }
  338.     return cp;
  339. }
  340.